package com.zhongli.devplatform.controller.im;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zhongli.devplatform.dto.im.IMUserInitDTO;
import com.zhongli.devplatform.po.common.ReadNoticePO;
import com.zhongli.devplatform.po.user.ReadUserInfoPO;
import com.zhongli.devplatform.po.user.ReadUserPO;
import com.zhongli.devplatform.service.imp.im.IMRestAPIService;
import com.zhongli.devplatform.service.imp.user.ReadUserInfoService;
import com.zhongli.devplatform.service.imp.user.ReadUserService;
import com.zhongli.devplatform.utils.im.IMMessageUtil;
import com.zhongli.devplatform.bean.Res;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jodd.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * 腾讯云 IM RestAPI 转发控制器
 * @author WuXiCheng
 * @version 1.0
 */
@Api(tags = "腾讯云 IM RestAPI", description = "腾讯云 IM RestAPI")
@RestController
@RequestMapping("/im/api")
public class IMRestAPIController {

    @Autowired
    private IMRestAPIService imRestAPIService;

    /**
     * 服务器转发 RestAPI 请求
     * @param serviceName   接口名称
     * @param jobj          body
     * @return
     */
    @ApiOperation("统一服务器转发RestAPI请求")
    @PostMapping("/{serviceName}")
    public Res<JSONObject> dispatcher(@PathVariable String serviceName, @RequestBody JSONObject jobj){
        return imRestAPIService.dispatcher(serviceName, jobj);
    }

    /**
     * 根据名称模糊查询用户
     * @param nick
     * @return
     */
    @ApiOperation("模糊查询用户")
    @GetMapping("/findByNick")
    public Res findByNick(String nick){
        return imRestAPIService.findByNick(nick);
    }

    /**
     * 导入账号
     * @return
     */
    @ApiOperation("导入im系统账号")
    @PostMapping("/accountImport")
    public Res<JSONObject> accountImport(@RequestBody JSONObject jobj){
        return  imRestAPIService.dispatcher("ACCOUNT_IMPORT", jobj);
    }

    /**
     * 删除账号
     * @return
     */
    @ApiOperation("删除im系统账号")
    @PostMapping("/accountDelete")
    public Res<JSONObject> accountDelete(@RequestBody JSONObject jobj){
        return  imRestAPIService.dispatcher("ACCOUNT_DELETE", jobj);
    }
}
